home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / pl1 / pi < prev    next >
Text File  |  1989-04-22  |  5KB  |  221 lines

  1. CLRSCR;
  2. PRINT(SYSPRINT,REPEAT(' ',30),'Computation of Pi');
  3. PUTCRLF; PUTCRLF; PUTCRLF;
  4. n=1;
  5. DO WHILE(n > 0);
  6.   PRINT(SYSPRINT,'Number of decimal places (0 to exit)?  ');
  7.   n=getint;
  8.   IF n > 0 THEN
  9.     DO;
  10.       n_plus_1=n+1;
  11.       PRINT(SYSPRINT,'pi = ');
  12.       m=n+3;
  13.       i=2*m-1;
  14.       d1=25;
  15.       d2=239;
  16.       k=0;
  17.       k_mod_5=-1;
  18.       group_mod_12=1;
  19.       p(1)=0;
  20.       p(2)=0;
  21.       p(3)=0;
  22.       x(1)=3;
  23.       x(2)=2;
  24.       x2(1)=4;
  25.       x2(2)=0;
  26.       j=3;
  27.       DO WHILE(j <= m);
  28.         p(j)=0;
  29.         x(j)=0;
  30.         x2(j)=0;
  31.         j=j+1;
  32.       END;
  33.       r=0;
  34.       j=1;
  35.       DO WHILE(j <= m);
  36.         v=r*10+x2(j);
  37.         jd1=v/d2;
  38.         x2(j)=jd1;
  39.         r=v-d2*jd1;
  40.         j=j+1;
  41.       END;
  42.       d=1;
  43.       DO WHILE(d <= i);
  44.         r=0;
  45.         j=1;
  46.         DO WHILE(j<=m);
  47.           v=r*10+x(j);
  48.           jd1=v/d;
  49.           y(j)=jd1;
  50.           r=v-d*jd1;
  51.           j=j+1;
  52.         END;
  53.         j=m;
  54.         DO WHILE(j >= 1);
  55.           p(j)=p(j)+y(j);
  56.           IF p(j) > 9 THEN
  57.             DO;
  58.               p(j)=p(j)-10;
  59.               p(j-1)=p(j-1)+1;
  60.             END;
  61.           j=j-1;
  62.         END;
  63.         r=0;
  64.         j=1;
  65.         DO WHILE(j <= m);
  66.           v=r*10+x(j);
  67.           jd1=v/d1;
  68.           x(j)=jd1;
  69.           r=v-d1*jd1;
  70.           j=j+1;
  71.         END;
  72.         dd=d+2;
  73.         r=0;
  74.         j=1;
  75.         DO WHILE(j<=m);
  76.           v=r*10+x(j);
  77.           jd1=v/dd;
  78.           y(j)=jd1;
  79.           r=v-dd*jd1;
  80.           j=j+1;
  81.         END;
  82.         j=m;
  83.         DO WHILE(j >= 1);
  84.           p(j)=p(j)-y(j);
  85.           IF p(j) < 0 THEN
  86.             DO;
  87.               p(j)=p(j)+10;
  88.               p(j-1)=p(j-1)-1;
  89.             END;
  90.           j=j-1;
  91.         END;
  92.         r=0;
  93.         j=1;
  94.         DO WHILE(j <= m);
  95.           v=r*10+x(j);
  96.           jd1=v/d1;
  97.           x(j)=jd1;
  98.           r=v-d1*jd1;
  99.           j=j+1;
  100.         END;
  101.         r=0;
  102.         j=1;
  103.         DO WHILE(j <= m);
  104.           v=r*10+x2(j);
  105.           jd1=v/d;
  106.           y(j)=jd1;
  107.           r=v-d*jd1;
  108.           j=j+1;
  109.         END;
  110.         j=m;
  111.         DO WHILE(j >= 1);
  112.           p(j)=p(j)-y(j);
  113.           IF p(j) < 0 THEN
  114.             DO;
  115.               p(j)=p(j)+10;
  116.               p(j-1)=p(j-1)-1;
  117.             END;
  118.           j=j-1;
  119.         END;
  120.         r=0;
  121.         j=1;
  122.         DO WHILE(j <= m);
  123.           v=r*10+x2(j);
  124.           jd1=v/d2;
  125.           x2(j)=jd1;
  126.           r=v-d2*jd1;
  127.           j=j+1;
  128.         END;
  129.         r=0;
  130.         j=1;
  131.         DO WHILE(j <= m);
  132.           v=r*10+x2(j);
  133.           jd1=v/d2;
  134.           x2(j)=jd1;
  135.           r=v-d2*jd1;
  136.           j=j+1;
  137.         END;
  138.         dd=d+2;
  139.         r=0;
  140.         j=1;
  141.         DO WHILE(j <= m);
  142.           v=r*10+x2(j);
  143.           jd1=v/dd;
  144.           y(j)=jd1;
  145.           r=v-dd*jd1;
  146.           j=j+1;
  147.         END;
  148.         j=m;
  149.         DO WHILE(j >= 1);
  150.           p(j)=p(j)+y(j);
  151.           IF p(j) > 9 THEN
  152.             DO;
  153.               p(j)=p(j)-10;
  154.               p(j-1)=p(j-1)+1;
  155.             END;
  156.           j=j-1;
  157.         END;
  158.         r=0;
  159.         j=1;
  160.         DO WHILE(j <= m);
  161.           v=r*10+x2(j);
  162.           jd1=v/d2;
  163.           x2(j)=jd1;
  164.           r=v-d2*jd1;
  165.           j=j+1;
  166.         END;
  167.         r=0;
  168.         j=1;
  169.         DO WHILE(j <= m);
  170.           v=r*10+x2(j);
  171.           jd1=v/d2;
  172.           x2(j)=jd1;
  173.           r=v-d2*jd1;
  174.           j=j+1;
  175.         END;
  176.         k=k+1;
  177.         IF k <= n_plus_1 THEN
  178.           DO;
  179.             k_mod_5=k_mod_5+1;
  180.             IF k_mod_5 > 5 THEN
  181.               DO;
  182.                 k_mod_5=1;
  183.                 group_mod_12=group_mod_12+1;
  184.                 IF group_mod_12 > 12 THEN
  185.                   DO;
  186.                     group_mod_12=1;
  187.                     PUTCRLF(SYSPRINT);
  188.                     PRINT(SYSPRINT,'       ');
  189.                   END;
  190.                 ELSE
  191.                   PRINT(SYSPRINT,' ');
  192.               END;
  193.               PRINT(SYSPRINT,p(k));
  194.             IF k = 1 THEN
  195.               PRINT(SYSPRINT,'.');
  196.           END;
  197.         k=k+1;
  198.         IF k <= n_plus_1 THEN
  199.           DO;
  200.             k_mod_5=k_mod_5+1;
  201.             IF k_mod_5 > 5 THEN
  202.               DO;
  203.                 k_mod_5=1;
  204.                 group_mod_12=group_mod_12+1;
  205.                 IF group_mod_12 > 12 THEN
  206.                   DO;
  207.                     group_mod_12=1;
  208.                     PUTCRLF(SYSPRINT);
  209.                     PRINT(SYSPRINT,'       ');
  210.                   END;
  211.                 ELSE
  212.                   PRINT(SYSPRINT,' ');
  213.               END;
  214.             PRINT(SYSPRINT,p(k));
  215.           END;
  216.         d=d+4;
  217.       END;
  218.       PUTCRLF(SYSPRINT);
  219.   END;
  220. END;
  221.